import 'package:course_control/config/styles.dart';
import 'package:course_control/widgets/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_utils/flutter_utils.dart';
import 'package:flutter_widgets/flutter_widgets.dart';
import 'package:from_css_color/from_css_color.dart';

import '../../../../config/com_header.dart';
import '../../../../gen/assets.gen.dart';

class VoiceCard extends StatefulWidget {
  const VoiceCard({super.key});

  @override
  State<VoiceCard> createState() => _VoiceCardState();
}

class _VoiceCardState extends State<VoiceCard> {
  var voiceValue = 0.0;
  var recordValue = 0.0;

  void onChanged(double value, int index) {
    if (index == 0) {
      voiceValue = value;
    } else {
      recordValue = value;
    }
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return TransparentContain(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          _buildItem(Assets.images.voice.path, '音响', 0, voiceValue),
          // _buildItem(Assets.images.record.path, '麦克风', 1, recordValue),
        ],
      ),
    );
  }

  Widget _buildItem(String imgPath, String title, int index, double value) {
    return Row(children: [
      SizedBox(
        width: 70.ratio,
        child: Text(
          title,
          style: TextStyles.textStyle20,
        ),
      ),
      Expanded(
        child: Slider(
            thumbColor: Colors.white,
            activeColor: YJColors.primaryColor,
            inactiveColor: fromCssColor('#13231D').withOpacity(0.8),
            value: value,
            onChanged: (value) => onChanged(value, index)),
      ),
      CommonImage.asset(
        imgPath,
        width: 48.ratio,
      )
    ]);
  }
}
